<!-- eslint-disable vue/multi-word-component-names -->
<script setup lang="ts">
import { useAppStore } from '@/pinia/stores/app'
// import { useSettingsStore } from '@/pinia/stores/settings'
import { useUserStore } from '@/pinia/stores/user'
import { Breadcrumb, Hamburger } from '..'
import { UserFilled } from '@element-plus/icons-vue'
// import { useDevice } from '@/composables/useDevice'
// import { useLayoutMode } from '@/composables/useLayoutMode'
import Notify from '@/components/Notify/index.vue'
import Screenfull from '@/components/Screenfull/index.vue'
import SearchMenu from '@/components/SearchMenu/index.vue'
import ThemeSwitch from '@/components/ThemeSwitch/index.vue'

// const { isMobile } = useDevice()
// const { isTop } = useLayoutMode()
const router = useRouter()
const appStore = useAppStore()
const userStore = useUserStore()
// const settingsStore = useSettingsStore()

const logout = () => {
  userStore.logout()
  router.push('/login')
}

const toggleSidebar = () => {
  appStore.toggleSidebar(false)
}
</script>

<template>
  <div class="navigation-bar">
    <Hamburger
      :is-active="appStore.sidebar.opened"
      @toggle-click="toggleSidebar"
      class="hamburger"
    ></Hamburger>
    <Breadcrumb class="breadcrumb"></Breadcrumb>
    <!-- <Sidebar v-if="isTop && !isMobile" class="sidebar" /> -->
    <div class="right-menu">
      <SearchMenu class="right-menu-item"></SearchMenu>
      <Screenfull class="right-menu-item"></Screenfull>
      <ThemeSwitch class="right-menu-item"></ThemeSwitch>
      <Notify class="right-menu-item"></Notify>
      <el-dropdown>
        <div class="right-menu-item user">
          <el-avatar :icon="UserFilled" :size="30" />
          <span>{{ userStore.username }}</span>
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <a target="_blank" href="https://github.com/un-pany/v3-admin-vite">
              <el-dropdown-item>GitHub</el-dropdown-item>
            </a>
            <a target="_blank" href="https://gitee.com/un-pany/v3-admin-vite">
              <el-dropdown-item>Gitee</el-dropdown-item>
            </a>
            <el-dropdown-item divided @click="logout">
              退出登录
            </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.navigation-bar {
  display: flex;
  height: var(--v3-navigationbar-height);
  overflow: hidden;
  color: var(--v3-navigationbar-text-color);
  display: flex;
  justify-content: space-between;

  .hamburger {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 15px;
    cursor: pointer;
  }
  .breadcrumb {
    flex: 1;
    // 参考 Bootstrap 的响应式设计将宽度设置为 576
    @media screen and (max-width: 576px) {
      display: none;
    }
  }

  .right-menu {
    margin-right: 10px;
    height: 100%;
    display: flex;
    align-items: center;
    &-item {
      margin: 0 10px;
      cursor: pointer;
      &:last-child {
        margin-left: 20px;
      }
    }
    .user {
      display: flex;
      align-items: center;
      .el-avatar {
        margin-right: 10px;
      }
      span {
        font-size: 16px;
      }
    }
  }
}
</style>
